//
//  SingleViewController.m
//  UIPickerViewDemo
//
//  Created by student on 16/2/23.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "SingleViewController.h"

@interface SingleViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>

@property (nonatomic,strong) NSArray *list;


@end

@implementation SingleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.list = @[@"吃饭",@"睡觉",@"打游戏",@"吃豆豆"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)btnPressed:(id)sender
{
    int sel = [self.pickerView selectedRowInComponent:0];// 第0列选择了几项
    NSString *name = self.list[sel];// 通过第几项
    
    UIAlertView *alerview = [[UIAlertView alloc] initWithTitle:@"跟着哥哥一起" message:name delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
    [alerview show];
    
}


// 有几列
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

// 第几列有几行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return self.list.count;
}

// 告诉Pickerview第几行第几列的内容是什么
- (nullable NSString *)pickerView:(UIPickerView *)pickerView
                      titleForRow:(NSInteger)row
                     forComponent:(NSInteger)component
{
    return self.list[row];
}

// 选择pickView内容的时候触发的事件
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    self.infoLabel.text = self.list[row];
}
@end
